package com.lc.testScript;

import com.lc.bean.ResponseBean;
import com.lc.util.*;
import com.relevantcodes.extentreports.ExtentReports;
import org.apache.http.client.CookieStore;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.testng.Assert;
import org.testng.annotations.*;

import java.io.IOException;
import java.util.Map;

/**
 * Created by 000001159 on 2016/8/16.
 */
public class GetCustomInfoTest extends BaseClass {


    static CookieStore cookieStore ;
    static CookieUtil cookieUtil=new CookieUtil() ;
    CloseableHttpClient client;
    HttpUtils httpUtils=HttpUtils.getInstance();
    ExtentReports extent;

    @Parameters({ "url", "objBean" ,"statusCode","xmlName"})
    @BeforeSuite

	/*
	* 登录进入系统获取JSESSIONID放入到CookieStore中
	* */
    public void beforeSuite(String url ,String objBean, String statusCode,String xmlName){
        this.befores(extent);
        cookieStore=this.LoginIn(url,objBean,statusCode,xmlName,httpUtils,cookieStore,cookieUtil);

    }

    @Parameters({ "url", "objBean" ,"statusCode","body","xmlName"})
    @Test(priority = 2)
    public  void TestGetCustomInfo(String url ,String objBean, String statusCode,String body,String xmlName) {
        Map<String,String> params=xmlUtil.readXMLDocument(objBean,xmlName);

        client = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
        CloseableHttpResponse httpResponse= httpUtils.post(url, params, client, cookieStore);
        ResponseBean rb=new ReponseUtil().setResponseBean(httpResponse);


//		add Assert
        Assert.assertEquals("OK", rb.getStatus());
        Assert.assertEquals(statusCode, rb.getStatusCode());
        Assert.assertEquals(true, rb.getBody().contains(body));

    }



    @AfterSuite
    public void afterSuite(){
        this.closeClient(client);

    }




}
